package leetcod_300;

public class leetCode_6_Reverse_Integer {
    //解法一
    public int reverse1(int x) {
        int rev = 0;
        while (x != 0) {
            if (x > Integer.MAX_VALUE) return 0;
            if (x < Integer.MIN_VALUE) return 0;
            int pop = x % 10;
            x = x / 10;
            rev = rev * 10 + pop;
        }
        return rev;
    }

    //解法一练习
    public int testreverse1(int x) {
        int rev = 0;
        while (x != 0) {
            if (x > Integer.MAX_VALUE) return 0;
            if (x < Integer.MIN_VALUE) return 0;
            int pop = x % 10;
            x = x / 10;
            rev = rev * 10 + pop;
        }
        return rev;
    }

    //解法二
    public int reverse2(int x) {
        long rev = 0;
        while (x != 0) {
            int pop = x % 10;
            x /= 10;
            rev = rev * 10 + pop;
        }
        if (rev > Integer.MAX_VALUE || rev < Integer.MIN_VALUE) return 0;
        return (int) rev;
    }

    //解法二练习
    public int testreverse2(int x) {
        long rev = 0;
        while (x != 0) {
            int pop = x % 10;
            x /= 10;
            rev = rev * 10 + pop;
        }
        if (rev > Integer.MAX_VALUE || rev < Integer.MIN_VALUE) return 0;
        return (int) rev;
    }


}
